package com.itheima.service.db.impl;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.db.UserService;
import org.apache.dubbo.config.annotation.DubboService;
import com.itheima.service.db.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@DubboService
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public Long save(User user) {

        String password = SecureUtil.md5(user.getPassword());

        user.setPassword(password);

        user.setCreated(new Date());

        user.setUpdated(new Date());

        userMapper.insert(user);

        return user.getId();
    }


    @Override
    public User findByPhone(String phone) {

        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();

        queryWrapper.eq("mobile", phone);

        return userMapper.selectOne(queryWrapper);
    }
}
